' 
' Copyright (C) 2014 Infinity CCS Ltd (http://www.infinityccs.com/)
' Copyright (C) 2007 Sasa Coh <sasacoh@gmail.com>
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program.  If not, see <http://www.gnu.org/licenses/>. 
'/


Imports Infinity.pjsipNET.Common
Imports Infinity.pjsipNET.Common.CallState

Namespace CallControl.CallState

#Region "Active"
  ''' <summary>
  ''' Active state indicates conversation. 
  ''' </summary>
  Friend Class Active
    Inherits IState
    Public Sub New(sm As CallMachine)
      MyBase.New(sm)
      Id = EStateId.ACTIVE
    End Sub

    Friend Overrides Sub OnEntry()
      _smref.Counting = True
      MediaProxy.stopTone()
    End Sub

    Friend Overrides Sub OnExit()

    End Sub

    Public Overrides Function endCall() As Boolean
      _smref.ChangeState(EStateId.TERMINATED)
      CallProxy.endCall()
      Return MyBase.endCall()
    End Function

    Public Overrides Function holdCall() As Boolean
      _smref.HoldRequested = True
      Return CallProxy.holdCall()
    End Function

    Public Overrides Function xferCall(number As String) As Boolean
      Return CallProxy.xferCall(number)
    End Function

    Public Overrides Function xferCallSession(partnersession As Integer) As Boolean
      Return CallProxy.xferCallSession(partnersession)
    End Function

    Public Overrides Sub onHoldConfirm()
      '// check if Hold requested
      If (_smref.HoldRequested) Then
        _smref.ChangeState(EStateId.HOLDING)
        '// activate pending action if any
        _smref.ActivatePendingAction()
      End If
      _smref.HoldRequested = False
    End Sub

    ''' <summary>
    ''' 
    ''' </summary>
    Public Overrides Sub onReleased()
      _smref.ChangeState(EStateId.RELEASED)
    End Sub

    Public Overrides Function conferenceCall() As Boolean
      Return CallProxy.conferenceCall()
    End Function
  End Class
#End Region

End Namespace
